package com.cheung.shopkeeper.common.utils;

import java.util.Stack;


/**
 * 这里面放了一些threadlocal的变量，大部分是被spring的切片放进来的，以方便后续的使用
 * 
 * @author chen
 * 
 */
public class SpringThreadLocalHelper {

    /**
     * 和AutoMapperName这个annotation配合使用，会将mybatis用到的mapper的名字放到这里 一般的命名规则都是PO的全类名加上拦截器拦到的函数名
     * 这里存放拦截器拦到的函数名
     */
    private static final ThreadLocalTemplate<Stack<String>> mybatisMapperNameStack = new ThreadLocalTemplate<Stack<String>>();
    

    public static final void pushMybatisMapperName(String name) {
        Stack<String> tmpStack = mybatisMapperNameStack.get();
        if (tmpStack == null) {
            tmpStack = new Stack<String>();
            mybatisMapperNameStack.set(tmpStack);
        }
        tmpStack.push(name);
    }

    public static final void popMybatisMapperName() {
        Stack<String> tmpStack = mybatisMapperNameStack.get();
        tmpStack.pop();
    }

    public static final String getMybatisMapperName() {
        Stack<String> tmpStack = mybatisMapperNameStack.get();
        return tmpStack.peek();
    }

    
}
